import book.Library;
import user.ProxyUser;
import user.User;
import user.factory.AdminUserFactory;
import user.factory.IUserfactory;
import user.factory.NormalUserFactory;

import java.util.Scanner;

public class LibrarySystem {
    public ProxyUser selectProxyUser(ProxyUser adminUser1,ProxyUser normalUser1,ProxyUser normalUser2) {
        System.out.println("选择角色进行登录: ");
        System.out.println("1.管理员(张三)\n2.普通用户(李四)\n3.普通用户(王五)\n4.退出系统");

        ProxyUser currentUser = null;
        Scanner sc = new Scanner(System.in);
        int choice = sc.nextInt();

        switch (choice) {
            case 1:
                currentUser = adminUser1;
                break;
            case 2:
                currentUser = normalUser1;
                break;
            case 3:
                currentUser = normalUser2;
                break;
            case 4:
                System.out.println("系统已退出..........");
                System.exit(0);
                break;
            default:
                System.out.println("选择错误,请重新选择:\n");
                selectProxyUser(adminUser1,normalUser1,normalUser2);
        }
        return currentUser;
    }

    public static void main(String[] args) {
        //用工厂方法来创建实例用户
        IUserfactory adminUserFactory = new AdminUserFactory();
        User adminUser1 = adminUserFactory.createUSer("张三",1);

        IUserfactory normalUserFactory = new NormalUserFactory();
        User normalUser1 = normalUserFactory.createUSer("李四",2);
        User normalUser2 = normalUserFactory.createUSer("王五",3);

        //创建代理类实例来代理管理员和普通用户
        ProxyUser proxyUserAdmin1 = new ProxyUser(adminUser1);
        ProxyUser proxyUserNormal1 = new ProxyUser(normalUser1);
        ProxyUser proxyUserNormal2 = new ProxyUser(normalUser2);

        //选择角色进行登录
        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectProxyUser(proxyUserAdmin1,proxyUserNormal1,proxyUserNormal2);

        //执行选项操作
        while(true) {
            int choice = currentUser.getRealUser().display();
            currentUser.handleOperation(choice);
        }
    }
}
